<?php
include_once("../configure/admin.config.inc.php");//--> admin global var
include_once("db.inc.php");						//--> db global var
include_once("Users.php");						//--> User
include_once("Operation.php");					//--> Operation
include_once("UserGroup.php");					//--> Menu group class
require_once("controlHeader.php");				//--> system control header

$objOperate		= new Operation($objSession->getLanguage());		//--> Operation instance
$objUserGroup 	= new UserGroup($objSession->getLanguage(), $objSession->getUserID());		//--> Menu group instance
$objUser 		= new Users($uid);									//--> user

$arrOperate 	= $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);

if(isset($_GET['id']) && !empty($_GET['id'])){
	$id = $_GET['id'];

	if($gid == $id){
		$error_message = 'invalid delete user group.';
	}else if(count($objUser->lists($arrOperate, " WHERE groupid=$id", 1, 1, '')) > 0) {
		$error_message = "can't delete the user group, because that have user above the user group.";
	}else{
		$isReturn = $objUserGroup->delete($arrOperate, $id);
		if($isReturn)
			$error_message = 'delete group successfully.';
		else 
			$error_message = 'delete group fail.';
	}
}

echo "<script language='javascript'>";
echo "alert(\"$error_message\");";
echo "location.href=\"".$_SERVER['HTTP_REFERER']."\";";
echo "</script>";

//$backurl = $_SERVER['HTTP_REFERER'];
//header("Location: $backurl");
?>
